<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>省份城市联动</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        .container {
            width: 400px;
            margin: 20px auto;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        select {
            width: 150px;
            padding: 5px;
            margin: 10px;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>省份城市联动示例</h2>
    <select id="province">
        <option value="">请选择省份</option>
        <option value="gd">广东省</option>
        <option value="zj">浙江省</option>
        <option value="js">江苏省</option>
    </select>

    <select id="city">
        <option value="">请选择城市</option>
    </select>
</div>

<script>
    $(document).ready(function() {
        // 城市数据
        var cityData = {
            'gd': ['广州', '深圳', '珠海', '东莞'],
            'zj': ['杭州', '宁波', '温州', '绍兴'],
            'js': ['南京', '苏州', '无锡', '常州']
        };

        // 省份选择变化时
        $('#province').change(function() {
            var provinceCode = $(this).val();
            var cities = cityData[provinceCode] || [];

            // 清空城市下拉框
            $('#city').empty().append('<option value="">请选择城市</option>');

            // 添加城市选项
            $.each(cities, function(index, city) {
                $('#city').append($('<option>').val(city).text(city));
            });
        });
    });
</script>
</body>
</html>